package com.sinosoft.common.encrypt.config;

import com.sinosoft.common.encrypt.filter.SimpleCryptoFilter;
import com.sinosoft.common.encrypt.properties.ApiDecryptProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 加密自动配置
 */
@Configuration
@EnableConfigurationProperties(ApiDecryptProperties.class)
@ConditionalOnProperty(value = "api-decrypt.enabled", havingValue = "true")
public class EncryptAutoConfiguration {

    @Bean
    public FilterRegistrationBean<SimpleCryptoFilter> cryptoFilterRegistration(ApiDecryptProperties properties) {
        FilterRegistrationBean<SimpleCryptoFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new SimpleCryptoFilter(properties));
        registration.addUrlPatterns("/*");
        registration.setName("simpleCryptoFilter");
        registration.setOrder(1);
        return registration;
    }
} 